package com.wly.sound
{
	import com.wly.datapool.DataPool;
	
	import flash.media.Sound;
	import flash.media.SoundChannel;

	public class SoundManager
	{
		static public var SpringSound:String = "spring";
		static public var ButtonSound1:String = "button1";
		static public var ButtonSound2:String = "button2";
		static public var DrawLine:String     = "drawLine";
		static public var CoinSound:String         = "coin";
		static public var TreeHit:String      = "treehit";
		
		private var _bgSound:Sound;
		private var _bgSoundChanel:SoundChannel;
		static private var _instance:SoundManager;
		
		static public function get instance():SoundManager
		{
			if(!_instance)
			{
				_instance = new SoundManager();
			}
			
			return _instance;
		}
		
		public function init():void
		{
			if(!DataPool.getInstance().setting.bgSoundOff)
			{
				playBgSound();
			}
		}
		
		public function playBgSound():void
		{
			if(_bgSoundChanel)
			{
				return;
			}
			if(!_bgSound)
			{
				_bgSound = new SceneMusic();
			}
			
			_bgSoundChanel = _bgSound.play();
		}
		
		public function stopBgSound():void
		{
			if(_bgSoundChanel)
			{
				_bgSoundChanel.stop();
				_bgSoundChanel = null;
			}
		}
		
		public function playEffectSound(val:String):void
		{
//			if(DataPool.getInstance().setting.effectSoundOff)
//			{
//				return;
//			}
			
			var sound:Sound;
			switch(val)
			{
				case SpringSound:
					sound = new SpringEffectSound();
					break;
				case ButtonSound1:
					sound = new ButtonSoundOne();
					break;
				case ButtonSound2:
					sound = new ButtonSoundTwo();
					break;
				case CoinSound:
					sound = new CoinEffectSound();
					break;
				case TreeHit:
					sound = new TreeHitSound();
					break;
				case DrawLine:
					sound = new DrawLineSound();
					break;
				default:
					break;
			}
			
			trace(this, "playEffectSound", val, sound);
			if(sound)
			{
				sound.play(0, 1);
			}
		}
	}
}